package com.ymatou.iapi.productquery.service;

import com.google.gson.reflect.TypeToken;
import com.ymatou.iapi.productquery.compare.ProductQueryInterface;
import com.ymatou.iapi.productquery.parameter.ProductInListDto;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class GetProductListBySellerIdCall extends YmatouAutoTestCall implements ProductQueryInterface{
	private static String opurl="api/Product/GetProductListBySellerId";
	
	public GetProductListBySellerIdCall(){
		super(EnvSetup.getSystemUrl("productquery"), opurl, "POST", "JSON");
	}
	
	
	@Override
	public void addDefHeader(){
		client.addHeader("Content-Type", "application/json");
	}
	
	 
	@Override
	public JSONObject search(List<String> catalogs) {
		JSONObject requestBean = this.getJsonBean(null);
		
		JsonBeanHelper.updateJsonBean(requestBean, MapUtil.hashMap("CatalogIdList", new JSONArray(catalogs)));
		
		return callAndGetReturnData(requestBean);
	}
	
	
	public JSONObject call(int sellerId,int pageIndex,int pageSize) {
		JSONObject requestBean = this.getJsonBean(null);
		
		JsonBeanHelper.updateJsonBean(requestBean, MapUtil.hashMap("sellerId",sellerId,"pageIndex",pageIndex,"pageSize",pageSize));
		
		return callAndGetReturnData(requestBean);
	}


	public ArrayList<ProductInListDto> getProductList()
	{
		ArrayList<ProductInListDto> data = null;
		try {
			String ProductList=getJsonObject().get("Data").getAsJsonObject().get("ProductList").getAsJsonArray().toString();
			data=(ArrayList<ProductInListDto>) FormatUtil.GSONToObject(ProductList, new TypeToken<ArrayList<ProductInListDto>>() {}.getType());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}
	public static void main(String[] args) {
		int a = 100 / 11;
		System.out.println(a);
	}
}
